/*
 * Copyright 2010-2012 Susanta Tewari. <freecode4susant@users.sourceforge.net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package coalescent.cef.pui;

import cef.event.Event;
import cef.pui.EventConstructionException;
import cef.pui.EventImpl;
import cef.pui.pob.Builder;
import cef.pui.pob.BuilderException;
import coalescent.cef.event.RunRecursionEvent;
import coalescent.cef.pui.pob.Builders_Coa;
import coalescent.data.meta.MetaInf_AC;
import coalescent.data.meta.MetaInf_Mngr;
import coalescent.model.PopGenModel;
import coalescent.recursion.RecursionListener;
import coalescent.statistic.AC;

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

/**
 * @author Susanta Tewari
 * @version 1.3
 * @history Created on Dec 6, 2010.
 * @since 1.3
 * @param <L>
 */
public abstract class RunRecursionEventImpl<L extends RecursionListener> extends EventImpl
        implements RunRecursionEvent<L> {

    private final Builder<PopGenModel> model_b;
    private final Builder<AC<?, ?>> ac_b;
    private final Builder<MetaInf_Mngr<MetaInf_AC>> metaInf_b;

    /**
     * @param props
     * @throws EventConstructionException
     */
    public RunRecursionEventImpl(final Properties props) throws EventConstructionException {

        super(props);

        model_b = Builders_Coa.of_Model_PopGen(props, "coalescent.builder.PopGenModel");
        ac_b    = Builders_Coa.of_AC(props, "coalescent.builder.AC");
        metaInf_b = Builders_Coa.of_MetaInf_Mngr_AC(props, "coalescent.MetaInf_AC",
                "coalescent.MetaInf");
    }

    @Override
    public PopGenModel getModel() throws BuilderException {
        return model_b.build();
    }

    @Override
    public AC<?, ?> getStatistic() throws BuilderException {
        return ac_b.build();
    }

    @Override
    public MetaInf_Mngr getMetaInf() {
        return metaInf_b.build();
    }

    /**
     *
     * Properties:
     * <ul>
     *     <li>{@code coalescent.builder.PopGenModel.delegate = coalescent.cef.pui.pob.Builders_Coa$Model_KC64 |coalescent.cef.pui.pob.Builders_Coa$Model_K69}</li>
     *     <li>{@code coalescent.builder.KC64.theta = valid double string as specified in } {@link Double#parseDouble(java.lang.String)}</li>
     *     <li>{@code coalescent.builder.K69.theta = valid double string as specified in } {@link Double#parseDouble(java.lang.String)}</li>
     *     <li>{@code coalescent.builder.AC.delegate = coalescent.cef.pui.pob.Builders_Coa$AC_KC64 | coalescent.cef.pui.pob.Builders_Coa$AC_K69_GT_File}</li>
     *     <li>{@code coalescent.builder.An.an = valid values are of the format f1^t1_f2^t2... where fi and ti are positive and represent the frequency domain, and the alleles on that frequency domain, respectively}</li>
     *     <li>{@code coalescent.builder.GeneTree.url = k69data:xml//URL }<a href="coalescent/cef/pui/pob/doc-files/k69data.xml.txt">file format</a>, must accompany the <a href="coalescent/cef/pui/pob/doc-files/k69data.xsd.txt">schema</a></li>
     *     <li>{@code coalescent.builder.RecursionComputers.exactProb = true | false}</li>
     *     <li>{@code coalescent.builder.RecursionComputers.configCounter = true | false}</li>
     *     <li>{@code coalescent.builder.RecursionComputers.genealogyCounter = true | false}</li>
     *     <li>{@code coalescent.builder.RecursionComputers.configBuilder = true | false}</li>
     *     <li>{@code coalescent.builder.RecursionComputers.genealogyBuilder = true | false}</li>
     * </ul>
     *
     * @version version
     * @since 1.4.0
     * @history Created on 03/24/2013
     * @author Susanta Tewari
     */
    public static class DEFAULT extends RunRecursionEventImpl<RecursionListener>
            implements RunRecursionEvent.DEFAULT {

        /** recursion computations builder */
        private final Builder<List<RecursionListener>> computations_b;

        public DEFAULT(final Properties props) throws EventConstructionException {

            super(props);

            super.processEventProperties(getImplementedEventInterfaces());

            computations_b = Builders_Coa.of_RecursionListeners(props,
                    "coalescent.builder.RecursionComputations");
        }

        @Override
        protected List<Class<? extends Event>> getImplementedEventInterfaces() {

            final List<Class<? extends Event>> result = new ArrayList<>(2);

            result.add(Event.class);
            result.add(RunRecursionEvent.DEFAULT.class);

            return result;
        }

        @Override
        public List<RecursionListener> getListeners() throws BuilderException {
            return computations_b.build();
        }
    }
}
